import { reqAddOrUpdateShopCart, reqGetGoodInfo } from "@/api"
import { getUUID } from "@/utils/uuid_token"
const state = {
    goodInfo:{},
    uuid_token:getUUID()

}
const mutations = {
    GOODINFO(state, goodInfo) {
        state.goodInfo = goodInfo
    }
}
const actions = {
    async getGoodInfo({commit},skuId){
        //console.log(skuId)
        let goodInfo = await reqGetGoodInfo(skuId)
        if(goodInfo.code == 200) {
            commit('GOODINFO', goodInfo.data)
        }
    }
}
const getters = {
    //路径导航简化的数据
    categoryView(state) {
        //比如:state.goodInfo初始状态空对象，空对象的categoryView属性值undefined
        //当前计算出的 categoryView属性值至少是一个空对象，假的报错不会有了。
        return state.goodInfo.categoryView || {};
    },
    //简化产品信息的数据
    skuInfo(state) {
        return state.goodInfo.skuInfo || {};
    },
    //产品售卖属性的简化
    spuSaleAttrList(state) {
        return state.goodInfo.spuSaleAttrList || [];
    },
}

export default {
    state,mutations,actions,getters
}